package geppetto.phraseTable.phrase.feature.calc.local;

import java.util.ArrayList;
import java.util.HashMap;

import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePairData;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.data.ReorderingData;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.data.ScoreData;
import geppetto.phraseTable.phrase.Phrase;
import geppetto.phraseTable.phrase.feature.AbstractFeature;
import geppetto.phraseTable.phrase.feature.ReorderingFeature;
import geppetto.reordering.ReorderingInfo;

public class WeightedReorderingFeatureCalc extends ReorderingFeatureCalc{
	protected final static String SCORE_HEADER = "score";
	protected final static String FEATURE = "wreord";
	
	public WeightedReorderingFeatureCalc(int order) {
		super(order);
	}

	@Override
	public void calculateFeature(ArrayList<Phrase> phrases) {
		for(int i = 0; i < phrases.size(); i++){
			Phrase p = phrases.get(i);
			ReorderingData rdata = (ReorderingData)p.getData(REORDERING_HEADER);
			double score = ((ScoreData)p.getData(SCORE_HEADER)).getScore();
			phrases.get(i)._features.addFeature(FEATURE, new ReorderingFeature(getPhraseReorderingFeatures(rdata.getReorderingInfo(), score)), order);
		}
	}
	
	public double[] getPhraseReorderingFeatures(ReorderingInfo info, double score) {
		double[] ret = super.getPhraseReorderingFeatures(info);
		for(int i = 0; i < ret.length; i++){
			ret[i] = ret[i] * score;
		}
		return ret;
	}
}
